package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.BaseIdDTO;
import com.winshare.saleAssistant.domain.dto.req.RegionCreateDTO;
import com.winshare.saleAssistant.domain.dto.req.RegionDeleteDTO;
import com.winshare.saleAssistant.domain.dto.req.RegionUpdateDTO;
import com.winshare.saleAssistant.service.RegionService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/region")
@CrossOrigin
@Api(value = "大区设置", description = "大区设置")
public class RegionController {

    private final RegionService regionService;

    public RegionController(RegionService regionService) {
        this.regionService = regionService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增大区接口")
    public LogicResponse save(@RequestBody @Validated RegionCreateDTO regionCreateDTO) {
        regionService.saveRegion(regionCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改大区接口")
    public LogicResponse update(@RequestBody @Validated RegionUpdateDTO regionUpdateDTO) {
        regionService.updateRegion(regionUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取所有大区列表")
    public LogicResponse getRegionList() {
        return LogicResponse.success(regionService.getRegionList());
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除某一个大区")
    public LogicResponse delete(@RequestBody @Validated RegionDeleteDTO regionDeleteDTO) {
        regionService.deleteRegion(regionDeleteDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "获取某个大区的详情")
    public LogicResponse getRegionDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(regionService.getRegionDetail(baseIdDTO));
    }
}


